import { Injectable } from '@angular/core';
import { HttpClient } from '@angular/common/http';

import { map } from "rxjs/operators";
@Injectable()
export class QkPartService {

    constructor(private http: HttpClient) { }

    /**加载人员树 */
    getUnitHumanTree(unitId: number, isRoot: boolean, isSupervise = "") {
        return this.http.get('/system/api/humaninfo/listtree?unitId=' + unitId + "&isRoot=" + isRoot + "&isSupervise=" + isSupervise).pipe(
            map((res: Response) => res['data'])
        );
    }

    /** 查询人员姓名 */
    searchUnitHumanByName(humanName: string) {
        return this.http.get('/system/api/humaninfo/search?name=' + humanName).pipe(
            map((res: Response) => res['data'])
        );
    }

    /** 获取组织机构树结构 */
    getUnitTree(unitId: number, isRoot: boolean, isSupervise = "") {
        return this.http.get('/system/api/unitinfo/listtree?unitId=' + unitId + "&isRoot=" + isRoot+ "&isSupervise=" + isSupervise).pipe(
            map((res: Response) => res['data'])
        )
    }

    /**根据下拉框查找机构信息 */
    searchUnitByName(name: string) {
        return this.http.get('/system/api/unitinfo/search?name=' + name).pipe(
            map((res: Response) => res['data'])
        )
    }

    /** 获取组织机构岗位树 */
    getUnitRoleTree(unitId: number, isRoot: Boolean) {
        return this.http.get('/system/api/roleinfo/listtree?unitId=' + unitId + "&isRoot=" + isRoot).pipe(
            map((res:Response) => res['data'])
        )
    }

    /** 根据名称查询机构或岗位 */
    searchUnitRoleByName(name: string) {
        return this.http.get('/system/api/roleinfo/search?name=' + name).pipe(
            map((res:Response) => res['data'])
        )
    }
}